import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

import { HttpClient } from '@angular/common/http';
import { ViewData } from '../faucet';
import { FaucetService } from '../faucet.service';

@Component({
  selector: 'app-index-view',
  templateUrl: './index-view.component.html',
  styleUrls: ['./index-view.component.css']
})



export class IndexViewComponent implements OnInit {

  constructor(private http: HttpClient,private faucetService:FaucetService,private fb:FormBuilder) { }
  validateForm!: FormGroup;
  showTotal = 1
  listOfRandomUser: ViewData[] = []
  pageSize = 100
  pageIndex = 2
  selectedValue = null;
  size = 'large'

  lastSort = (a: ViewData, b: ViewData) => a.lastPayment - b.lastPayment
  balanceSort = (a: ViewData, b: ViewData) => a.lastPayment - b.lastPayment
  hourSort = (a: ViewData, b: ViewData) => a.lastPayment - b.lastPayment
  dailySort = (a: ViewData, b: ViewData) => a.lastPayment - b.lastPayment

  getFaucet() {
    
    this.faucetService.getFaucet().subscribe(faucet=>{
      this.listOfRandomUser=faucet
      this.showTotal = faucet.length
    })
  }

  submitForm(){
    this.faucetService.getParamsFaucet(this.validateForm).subscribe(faucet=>this.listOfRandomUser=faucet)
  }


  ngOnInit(): void {
    this.getFaucet()
    this.validateForm = this.fb.group({
      name: ['',[Validators.required]],
      currencyName: ['', [Validators.required]],
    });
  }


}
